package controllers

import (
	"smart_home/admin/commons"
	"smart_home/admin/models"
)

type UserController struct {
	BaseController
}

// @title 列表
// @router /?:page [get]
func (c *UserController) List() {
	var page int64
	c.Ctx.Input.Bind(&page, ":page")
	if page == 0 {
		page = 1
	}

	lists, count, err := models.GetUserLists(map[string]interface{}{}, page)
	if err != nil {
		c.ErrorResponse(commons.ErrorDBError)
		return
	}

	c.SuccessResponse(map[string]interface{}{
		"count": count,
		"page":  page,
		"list":  lists,
	})
}

// @title 用户信息
// @router /info/:id [get]
func (c *UserController) Info() {
	var id string
	c.Ctx.Input.Bind(&id, ":id")

	user, err := models.GetUserById(id)
	if err != nil {
		c.ErrorResponse(commons.ErrorDBError)
		return
	}
	if user == nil {
		c.ErrorResponse(commons.ErrorUserNotExits)
		return
	}
	c.SuccessResponse(user)
}

// @title 每日注册的用户
// @router /everydata/:date
func (c *UserController) Everyday() {

}
